#pragma once
#include <stdio.h>
#include <fstream>
using namespace std;

extern char FILE_BUFF[];

class SunLogger {
private:
	char* _loggerName;
	ofstream fout;
public:
	SunLogger(char* loggerName) {
		this->_loggerName = loggerName;
		fout.open("D:\\SunTrader.log", ios::in | ios::out);
	}

	~SunLogger() {
		fout.close();
	}

	void info(char* msg) {
		SYSTEMTIME sys;
		GetLocalTime(&sys);
		sprintf_s(FILE_BUFF,BUFFER_SIZE,"%s info(%4d/%02d/%02d %02d:%02d:%02d.%03d):%s\n", this->_loggerName,sys.wYear,
			sys.wMonth, sys.wDay, sys.wHour, sys.wMinute,sys.wSecond,sys.wMilliseconds,msg);
		printf(FILE_BUFF);

		fout << FILE_BUFF << endl;
		fout.flush();
	}

	void error(char* msg) {
		SYSTEMTIME sys;
		GetLocalTime(&sys);
		sprintf_s(FILE_BUFF, BUFFER_SIZE, "%s error:%s\n", this->_loggerName, msg);
		printf(FILE_BUFF);

		fout << FILE_BUFF << endl;
		fout.flush();
	}

	void warn(char* msg) {
		SYSTEMTIME sys;
		GetLocalTime(&sys);
		sprintf_s(FILE_BUFF, BUFFER_SIZE, "%s warn:%s\n", this->_loggerName, msg);
		printf(FILE_BUFF);

		fout << FILE_BUFF << endl;
		fout.flush();
	}
};